package com.lx.chapter2.service;

import com.lx.chapter2.helper.DatabaseHelper;
import com.lx.chapter2.model.Customer;

import java.util.List;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;

/**
 * 提供客户数据服务
 *
 * @author 段誉
 * @create 2019-03-21 20:30
 */
@Slf4j
public class CustomerService {
  /**
   * 获取客户列表
   */
  public List<Customer> getCustomerList() {
    String sql = "SELECT * FROM customer";
    return DatabaseHelper.queryEntityList(Customer.class, sql);
  }

  /**
   * 获取客户信息
   */
  public Customer getCustomer(Long id) {
    String sql = "SELECT * FROM customer WHERE id=?";
    return DatabaseHelper.queryEntity(Customer.class, sql, id);
  }

  /**
   * 创建客户
   */
  public boolean createCustomer(Map<String, Object> fieldMap) {
    return DatabaseHelper.insertEntity(Customer.class, fieldMap);
  }

  /**
   * 编辑客户
   */
  public boolean updateCustomer(long id, Map<String, Object> fieldMap) {
    return DatabaseHelper.updateEntity(Customer.class, id, fieldMap);
  }

  /**
   * 删除客户
   */
  public boolean deleteCustomer(Long id) {
    return DatabaseHelper.deleteEntity(Customer.class, id);
  }


}
